#include<bits/stdc++.h>
using namespace std;
const int MAXN=30010;
int n,m,pre[MAXN],head[MAXN],cnt,maxv[MAXN*4],sumv[MAXN*4];
struct edge
{
	int v,next;
}e[MAXN*2];
struct point
{
	int num,sum,depth,fa,son,sub,top;
}p[MAXN];
void addedge(int x,int y)
{
	e[cnt]=(edge){y,head[x]};
	head[x]=cnt++;
}
void push_up(int o)
{
	int lc=o<<1,rc=o<<1|1;
	sumv[o]=sumv[lc]+sumv[rc];
	maxv[o]=max(maxv[lc],maxv[rc]);
}
void dfs1(int u,int last,int depth)
{
	int t=0;
	p[u].sum=1;
	p[u].fa=last;
	p[u].depth=depth;
	for(int i=head[u];~i;i=e[i].next)
	{
		if(e[i].v==last)continue;
		dfs1(e[i].v,u,depth+1);
		p[u].sum+=p[e[i].v].sum;
		if(p[e[i].v].sum>t)
		{
			t=p[e[i].v].sum;
			p[u].son=e[i].v;
		}
	}
	return;
}
void dfs2(int u,int last)
{
	p[u].top=last;
	pre[++cnt]=u;
	p[u].sub=cnt;
	if(p[u].son)dfs2(p[u].son,last);
	for(int i=head[u];~i;i=e[i].next)
	{
		if(e[i].v==p[u].son||e[i].v==p[u].fa)continue;
		dfs2(e[i].v,e[i].v);
	}
	return;
}
void build(int o,int l,int r)
{
	if(l==r)
	{
		sumv[o]=maxv[o]=p[pre[l]].num;
		return;
	}
	int lc=o<<1,rc=o<<1|1,mid=(l+r)>>1;
	build(lc,l,mid);
	build(rc,mid+1,r);
	push_up(o);
	return;
}
int query_sum(int o,int l,int r,int y1,int y2)
{
	if(l>=y1&&r<=y2)return sumv[o];
	int ret=0,lc=o<<1,rc=o<<1|1,mid=(l+r)>>1;
	if(y1<=mid)ret+=query_sum(lc,l,mid,y1,y2);
	if(y2>mid)ret+=query_sum(rc,mid+1,r,y1,y2);
	return ret;
}
int query_max(int o,int l,int r,int y1,int y2)
{
	if(l>=y1&&r<=y2)return maxv[o];
	int ret=-3e4,lc=o<<1,rc=o<<1|1,mid=(l+r)>>1;
	if(y1<=mid)ret=query_max(lc,l,mid,y1,y2);
	if(y2>mid)ret=max(ret,query_max(rc,mid+1,r,y1,y2));
	return ret;
}
void query(bool k,int u,int v)
{
	int ret=k?0:-3e4;
	while(1)
	{
		int f1=p[u].top,f2=p[v].top;
		if(f1==f2)
		{
			int k1=min(p[u].sub,p[v].sub),k2=max(p[u].sub,p[v].sub);
			if(k)ret+=query_sum(1,1,n,k1,k2);
			else ret=max(ret,query_max(1,1,n,k1,k2));
			break;
		}
		else if(p[f1].depth>=p[f2].depth)
		{
			if(k)ret+=query_sum(1,1,n,p[f1].sub,p[u].sub);
			else ret=max(ret,query_max(1,1,n,p[f1].sub,p[u].sub));
			u=p[f1].fa;
		}
		else
		{
			if(k)ret+=query_sum(1,1,n,p[f2].sub,p[v].sub);
			else ret=max(ret,query_max(1,1,n,p[f2].sub,p[v].sub));
			v=p[f2].fa;
		}
	}
	printf("%d\n",ret);
	return;
}
void update(int o,int l,int r,int u,int v)
{
	if(l==r)
	{
		maxv[o]=sumv[o]=p[pre[l]].num=v;
		return;
	}
	int lc=o<<1,rc=o<<1|1,mid=(l+r)>>1;
	if(u<=mid)update(lc,l,mid,u,v);
	else update(rc,mid+1,r,u,v);
	push_up(o);
	return;
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n-1;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	for(int i=1;i<=n;++i)scanf("%d",&p[i].num);
	dfs1(1,0,1);
	cnt=0;
	dfs2(1,1);
	build(1,1,n);
	scanf("%d",&m);
	while(m--)
	{
		char t1[10];
		int t2,t3;
		scanf("%s",t1);
		scanf("%d%d",&t2,&t3);
		if(t1[0]=='Q'&&t1[1]=='M')
			query(0,t2,t3);
		else if(t1[0]=='Q'&&t1[1]=='S')
			query(1,t2,t3);
		else update(1,1,n,p[t2].sub,t3);
	}
}
